package string_question.leecode.test28;

/**
 * 方法一： 暴力解法
 * 反而时间上更短
 * @author code_yc
 * @version 1.0
 * @date 2020/7/5 9:10
 */
public class Solution1 {

    public int strStr(String haystack, String needle) {
        if (needle.equals("")) return 0;
        int lenH = haystack.length();
        int lenN = needle.length();
        if (lenH < lenN) return -1;
        for (int i = 0; i <= lenH - lenN; i++) {
            if (haystack.substring(i, i + lenN).equals(needle)) {
                return i;
            }
        }
        return -1;
    }

}
